<template>
  <div class="ma-content-block">
	  
    <sa-table ref="crudRef" :options="options" :columns="columns" :searchForm="searchForm">
      <!-- 搜索区 tableSearch -->
      <template #tableSearch>
		  <a-col :span="8">
		    <a-form-item label="用户ID" field="user_id">
		      <a-input v-model="searchForm.user_id" placeholder="请输入用户ID" />
		    </a-form-item>
		  </a-col>
        <a-col :span="8">
          <a-form-item label="联系人" field="user_name">
            <a-input v-model="searchForm.user_name" placeholder="请输入联系人" />
          </a-form-item>
        </a-col>
		<a-col :span="8">
		  <a-form-item label="联系电话" field="contact_number">
		    <a-input v-model="searchForm.contact_number" placeholder="请输入联系电话" />
		  </a-form-item>
		</a-col>
		<a-col :span="8">
		<a-form-item label="留言类别" field="feedback_classify">
		  <a-select
		      v-model="searchForm.feedback_classify"
		      :options="postData"
		      allow-clear
		      placeholder="请选择产留言类别" />
		</a-form-item>
		 </a-col>
		 <a-col :span="8">
		   <a-form-item label="提交时间" field="create_time">
		     <a-range-picker v-model="searchForm.create_time" :show-time="true" mode="date" />
		   </a-form-item>
		 </a-col>
		 
      </template>
      <template #operationBeforeExtend="{ record }">
	    <a-link @click="openDetail(record)"   v-auth="['/feedback/feedback/detail']"> <icon-plus /> 查看 </a-link>
	  </template>
      <!-- Table 自定义渲染 -->
    </sa-table>

    <!-- 编辑表单 -->
    <edit-form ref="editRef" @success="refresh" />
	<add-form ref="addRef" @success="refresh" />
	<detail-form ref="detailRef" @success="refresh" />
  </div>
</template>

<script setup>
import { onMounted, ref, reactive } from 'vue'
import { Message } from '@arco-design/web-vue'
import EditForm from './edit.vue'
import addForm from './add.vue'
import detailForm from './detail.vue'
import api from '../api/feedback'
import commonApi from '@/api/common'
const postData = ref([])

// 引用定义
const crudRef = ref()
const editRef = ref()
const addRef = ref()
const detailRef = ref()
// 搜索表单
const searchForm = ref({
  user_id:'',	
  user_name: '',
  lang_code:'',
  contact_number:'',
  feedback_classify:'',
  create_time:''
})


// SaTable 基础配置
const options = reactive({
 api: (params) => api.getPageList({ ...params, ...searchForm.value }),
  pk: 'feedback_id',
  recycleApi: (params) => api.recycleApi({ ...params, ...searchForm.value }),
  rowSelection: { showCheckedAll: true },
  add: {
    show: false,
    auth: ['/feedback/feedback/save'],
    func: async () => {
     const currentLangCode = searchForm.value.lang_code;
     addRef.value?.open()
     addRef.value?.setFormData({lang_code:currentLangCode})
    },
  },
  edit: {
    show: true,
    auth: ['/feedback/feedback/update'],
	text:'回复',
    func: async (record) => {
      editRef.value?.open('edit')
      editRef.value?.setFormData(record)
    },
  },
  // delete: {
  //   show: true,
  //   auth: ['/feedback/feedback/destroy'],
  //   func: async (params) => {
  //     const resp = await api.delete(params)
  //     if (resp.code === 200) {
  //       Message.success(`删除成功！`)
  //       crudRef.value?.refresh()
  //     }
  //   },
  //   realAuth: ['/feedback/feedback/realDestroy'],
  //   realFunc: async (params) => {
  //     const resp = await api.realDestroy(params)
  //     if (resp.code === 200) {
  //       Message.success(`销毁成功！`)
  //       crudRef.value?.refresh()
  //     }
  //   },
  // },
  recovery: {
    show: true,
    auth: ['/feedback/feedback/recovery'],
    func: async (params) => {
      const resp = await api.recovery(params)
      if (resp.code === 200) {
        Message.success(`恢复成功！`)
        crudRef.value?.refresh()
      }
    },
  },
})

// SaTable 列配置
const columns = reactive([
  { title: '留言分类', dataIndex: 'feedback_classify_text', width: 180 },	
  { title: '用户名', dataIndex: 'user_name', width: 180 },
  { title: '联系电话', dataIndex: 'contact_number', width: 180 },
  { title: '反馈意见', dataIndex: 'feedback_content', width: 180 },
  { title: '状态', dataIndex: 'status',dict:'feedback_status', width: 180 },
  
  { title: '回复时间', dataIndex: 'reply_time', width: 180 },
])

// 页面数据初始化
const initPage = async () => {
  const postResp = await commonApi.commonGet('/cassification/ClassificationDictionary/getCate',{classification_type:9})
  postData.value = postResp.data
}
//jia
const openDetail = (record) => {
  detailRef.value?.open()
  detailRef.value?.setFormData(record)
}

// SaTable 数据请求
const refresh = async () => {
  crudRef.value?.refresh()
}

// 页面加载完成执行
onMounted(async () => {
  initPage()
  refresh()
})
</script>
